

export function downloadFile (res, name) {
  const url = window.URL.createObjectURL(new Blob([res]))
  const link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  const fileName = name
  link.setAttribute('download', fileName)
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
}

export const formatTime = (time,type) => {
  const date = new Date(time)
  const hour = String(date.getHours()).padStart(2, '0')
  const minute = String(date.getMinutes()).padStart(2, '0')
  const mm = String(date.getSeconds()).padStart(2, '0')
  const myyear = date.getFullYear()
  const mymonth = String((date.getMonth() + 1)).padStart(2, '0')
  const myweekday = String(date.getDate()).padStart(2, '0')
  if(type === 'Y-M-D'){
    return `${myyear}/${mymonth}/${myweekday}`
  }
  return `${myyear}-${mymonth}-${myweekday} ${hour}:${minute}:${mm}`
}

export const isMobile = () => {
  let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
  return flag;
}


export const randomString =(length)=> {
  var str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var result = '';
  for (var i = length; i > 0; --i)
    result += str[Math.floor(Math.random() * str.length)];
  return result;
}





